package com.bountytask.controller;

import com.alibaba.fastjson.JSONObject;
import com.bountytask.entity.Information;
import com.bountytask.service.InformationService;
import com.bountytask.service.impl.InformationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class InformationController {
    @Autowired
    private InformationService informationService;

    @DeleteMapping("information/_mdelete")
    public JSONObject mDeleteInformation(@RequestParam("ids[]") List<Long> ids){
        JSONObject resultJson = new JSONObject();
        if (informationService.getIds(ids).toString().equals(ids.toString())){
            informationService.mDeleteInfo(ids);
            resultJson.put("code",200);
            resultJson.put("message","成功");
        }
        else{
            resultJson.put("code",400);
            resultJson.put("message","失败");
        }
        return resultJson;
    }

    @PutMapping("information/viewed/{id}")
    public JSONObject setViewed(@PathVariable long id){
        JSONObject resultJson = new JSONObject();
        Information info= informationService.setViewed(id);
        if (info==null){
            resultJson.put("code",400);
            resultJson.put("message","失败");
        }else{
            resultJson.put("code",200);
            resultJson.put("message","成功");
            resultJson.put("data",info);
        }
        return resultJson;
    }
}
